(function(){
	var allMenuObject ;
	var cntIndex=1;
	var allExitObject ;

	var allChObject;
	var allPgObject;
	var allEpObject;

	var allGbObject;
	var gbIndex=-1;
	var gbsubIndex=-1;
	var gbMenu=0;

	var id=["stop","play","rewind","forward","view","option"];
	var videoArray=["http://211.115.205.18:8012/get_it_beauty_2013_ep18.mp4"];
	var videoArrayBg=["http://211.115.205.18:8012/ENEWS_EP1673_1000k.mp4"];
	// var videoArrayBg=["http://nscreen.catchon.cjenm.gscdn.com/Trailer/Mycatchon_Deadfall_1m27s.mp4"];
	var currentType="";
	var supportedMimeTypes = [".mp4", ".mpeg", ".wmv", ".asf"];
	var defaultClass=["stopButton","playButton","rewindButton","forwardButton","optionButton"];
	var exitBtnClass=["backKey","exitKey"];
	var video;
	var videoBg;

	var progressBarWidth;
	var TIME_FOR_SEEK = 10;
	var playTimerId;
	var hideTimerId;
	var rowID=1;
	var tempcntIndex=-1;
	var mouseDown=false;
	var videoPlayInfo ;
	var dragged=false;
	var vidIndex=0;
	var stopped=false;

	var menuID = 0;
	var chIndex = 3;
	var pgIndex = 1;
	var epIndex = -1;
	var plindex = 0;

	var tempchIndex = -1;
	var tempBg = "";

	// var chlist;
	// var currentItem;
	// var itemCount;

	var membership;
	var userLgoinId="";
	var loginResultVal = false;

	//$('document').ready(function() {
		//console.log(">>>> document.ready");
		// channel API Testing Code
		// var chAPI = "http://211.239.159.41/json/Data/ChannelList.asp?callback=?";
		/*
		var chAPI = "http://www.win-core.co.kr/test.asp?callback=?";
		  $.getJSON( chAPI, {
			transactionId: 12345,
			pageSize: 10,
			pageNo: 1,
			format: "json"
		  })
		  .done(function( data ) {
			 console.log(">>chAPI>> complete");
			 console.log(">>chAPI>> resultcode" + data.resultcode);
			 console.log(">>chAPI>> messge" + data.messge);
			 console.log(">>chAPI>> total_count" + data.total_count);
			 console.log(">>chAPI>> page_info" + data.page_info.page_size + " / " + data.page_info.page + " / " + data.page_info.total_page);
		  })
		  .fail(function() { console.log( "error" ); });
		  */

	//});

	//$(window).load(function(){
	$('document').ready(function() {
		// membership API
		membership = document.getElementById('membership');
		//loginResultVal = membership.isSignedInAccount();
		loginResultVal = false;
		if (loginResultVal) {
			$("#user").removeClass("logout").addClass("login");
			var result_object;
			result_object = membership.getUserID();
			userLgoinId = result_object.userID;
			$("#user b").html(userLgoinId);
		} else {
			userLgoinId = "";
		}

		$("#list h1 img").attr({"src":"img/tit_4.png"});
		$("#info h2 img").attr({"src":"img/tit_4.png"});

		// videoBg = getVideoBg();
		video = getVideo();
		// console.log("LOG>>>>>>>" + stopped);
		playMediaBg();

		allChObject = new Array();
		allPgObject = new Array();
		allEpObject = new Array();
		allGbObject = new Array();

		allMenuObject =new Array();
		allExitObject =new Array();

		//on mouseenter change the button color using classes of each control button respectively
		/*
		$("#wrap li,.btn_prev,.btn_next,.input,dl").each(function(i){
			$(this).on("mouseenter", function(event){
				$("#wrap li,.btn_prev,.btn_next,.input,dl").removeClass("focus");
				$(this).addClass("focus");
				//resetFocus();
			});
		});
		*/
		$("#ch li, #list li, #info .scroll li").each(function(i){
			$(this).on("mouseenter", function(event){
				$("#ch li, #list li, #info .scroll li").removeClass("focus");
				$(this).addClass("focus");
				gbMenu = 0;
				gbIndex = -1;
				gbsubIndex = -1;
			}).mouseleave(function() {
				$("#ch li, #list li, #info .scroll li").removeClass("focus");
			});
		});

		$("#global li").mouseenter(function(event) {
			$("#global li").removeClass("focus");
			$(this).addClass("focus");
			gbMenu = 1;
		}).mouseleave(function() {
			$("#global li").removeClass("focus");
			gbMenu = 0;
			gbIndex = -1;
			gbsubIndex = -1;
		});

		// on click of the Channel
		var elemCh = $("#ch li");
		$("#ch li").click(function() {
			if($(this).hasClass("select")){
				chIndex = $(this).index();
				// console.log(">>>>>>>>>> #ch li >> act.list");
				// console.log(">>>>>>>>>> #ch li >> chIndex : " + chIndex);
				act.list();
			} else {
				$("#ch li").removeClass("select");
				$(this).addClass("select");
				$("#ch ul").css({top : $(this).index() * -88}, 300);
				$("#list h1 img").attr({"src":"img/tit_"+($(this).index()+1)+".png"});
				$("#info h2 img").attr({"src":"img/tit_"+($(this).index()+1)+".png"});
				chIndex = $(this).index();
			}
		});
		for (i = 0; i < elemCh.length; i++) {
			allChObject.push(elemCh[i]);
		}

		// ch up
		/*
		$("#ch .up").click(function(){
			setFocus(-1);
			console.log(">>>>>>>>>> UP ");
		});
		*/
		// ch down
		/*
		$("#ch .down").click(function(){
			setFocus(1);
			console.log(">>>>>>>>>> DOWN ");
		});
		*/
		// ch up, down mouseover
		/*
		$("#ch .up, #ch .down").mouseover(function(){
			$("#ch li").removeClass("focus");
			$("#ch .up, down").removeClass("focus");
			$(this).addClass("focus");
		});
		*/
		// ch up, down mouseout
		/*
		$("#ch .up, #ch .down").mouseout(function(){
			$(this).removeClass("focus");
		});
		*/

		// on click of the Program
		var elemPg = $("#list li");
		$("#list li").click(function(){
			$("#list li").removeClass("select");
			$(this).addClass("select");
			$("#list ul").css({top : $(this).index() * -147},300);
			pgIndex = $(this).index();
		});
		$("#list ul").css({top : 1 * -147},300);
		for (i = 0; i < elemPg.length; i++) {
			allPgObject.push(elemPg[i]);
		}

		// on click of the Episode
		var elemEp = $("#info .scroll li");
		$("#info .scroll li").click(function(){
			$("#info .scroll li").removeClass("select");
			$(this).addClass("select");
			$("#info .scroll ul").css({top : $(this).index() * -50},300);
			epIndex = $(this).index();
		});
		for (i = 0; i < elemEp.length; i++) {
			allEpObject.push(elemEp[i]);
		}
		// console.log(">> elemEp : " + elemEp.length);

		/*
		$("#info .scroll,#info h2").click(function(){
			act.info();
		});
		*/
		$(".btn-back").click(function(){
			if(menuID == 1) {
				act.ch();
			} else if (menuID == 2) {
				act.list();
			}
		});

		$(".box-info ul li").mouseenter(function(event) {
			$(".box-info ul li").removeClass("focus");
			$(this).addClass("focus");
			plindex = 1;
		}).mouseleave(function() {
			$(".box-info ul li").removeClass("focus");
			plindex = 0;
		});

		$(".box-info ul li").click(function(){
			act.vod();
		});

		/*
		$("#wrap li,.btn_prev,.btn_next,.input,dl").mouseover(function(){
			$("#wrap li,.btn_prev,.btn_next,.input,dl").removeClass("focus");
			$(this).addClass("focus");
		});

		$(".popup .btn_prev,.popup  .btn_next").mouseout(function(){
			$(this).removeClass("focus");
		});
		*/

		$("#vod .menu ul li").click(function(){
			$("#vod .menu ul li").removeClass("on");
			$(this).addClass("on");
			$("#vod").removeClass("control list chart info");
			$("#vod").addClass($(this).attr("alt"));
		});

		$("#vod .menu ul li").mouseover(function(){
			var i = $(this).index()+1;
			$("#vod .menu").removeClass("m1 m2 m3 m4");
			$("#vod .menu").addClass("m"+i);
		});

		$("#vod .menu").hover(function(){
			$(this).addClass("hover");
		},function(){
			$(this).removeClass("hover");
		});

		$(".voice_ico,#pop_voice .cancel").click(function(){
			$("#pop_voice").toggle();
		});

		$("#vod .list ul li").click(function(){
			$("#vod .list ul li").removeClass("on");
			$(this).addClass("on");
			$("#vod .list").removeClass("dep1 dep2 dep3");
			$("#vod .list").addClass($(this).attr("alt"));
		});

		var elemGb = $("#global li");
		for (i = 0; i < elemGb.length; i++) {
			allGbObject.push(elemGb[i]);
		}

		$("#global .aside li").click(function(){
			gbsubIndex=3;
			$("#mask,#pop").show();
		});
		$(".popup .cancel").click(function(){
			$("#mask,#pop").hide();
		});
		$("#global .login").click(function(){
			gbsubIndex=0;
			$("#wrap").removeClass("search");
			if (loginResultVal) {
				$("#wrap").toggleClass("mypage");
			} else {
				membership.requestLogin();
				membership.onRequestLogin = eventRequestLogin;
			}
		});
		$("#global .logout").click(function(){
			gbsubIndex=0;
			$("#wrap").removeClass("search");
			if (loginResultVal) {
				$("#wrap").toggleClass("mypage");
			} else {
				membership.requestLogin();
				membership.onRequestLogin = eventRequestLogin;
			}
		});
		$("#global .search,#search .btn .cancel").click(function(){
			gbsubIndex=1;
			$("#wrap").removeClass("mypage");
			$("#wrap").toggleClass("search");
		});
		$("#global .event").click(function(){
			gbsubIndex=2;
			$("#wrap").removeClass("mypage search");
			$("#mask,#event").show();
		});

		$("#search .btn .symbol").click(function(){
			// $("#search").removeClass("result keypad voice");
			$("#search").removeClass("result voice");
			$("#search").addClass("voice");
		});
		$("#search .btn .submit").click(function(){
			//$("#search").removeClass("result keypad voice");
			$("#search").removeClass("result voice");
			$("#search").addClass("result");
		});
		/*
		$("#search .input").click(function(){
			$("#search").removeClass("result keypad voice");
			$("#search").addClass("keypad");
		});
		*/
		$("#mypage .tab li").click(function(){
			$("#mypage .tab li").removeClass("select");
			$(this).addClass("select");
			$("#mypage").removeClass("dep1 dep2");
			$("#mypage").addClass($(this).attr("alt"));
		});
		//pop
		$("#pop_type li").click(function(){
			var i = $(this).index() + 1;
			$(".popup").removeClass("on");
			$(".ly"+i).addClass("on");
			$("#pop_type li").removeClass("on");
			$(this).addClass("on");
			$("#pop_keypad").hide();
		});
		$(".popup .input").click(function(){
			$("#pop_keypad").show();
		});
		$(".poll ol li").click(function(){
			$(".poll ol li").removeClass("select");
			$(this).addClass("select");
		});
		//event
		$("#event .tab li").click(function(){
			$("#event .tab li").removeClass("on");
			$(this).addClass("on");
			var i = $(this).index() + 1;
			$("#event").removeClass("dep1 dep2 dep3 result");
			$("#event").addClass("dep"+i);
			$("#pop_keypad").hide();
		});
		$("#event .dep3 li").click(function(){
			$("#event").removeClass("dep1 dep2 dep3 result");
			$("#event").addClass("result");
		});
		$("#event .btn").click(function(){
			$("#event,#mask").hide();
		});
		//trans
		/*
		var key = ["key1","key2","key3"]
		var key_idx =0;
		$(".keypad .trans,#pop_keypad .trans").click(function(){
			key_idx++;
			$(this).parent().parent().removeClass("key1 key2 key3");
			$(this).parent().parent().addClass(key[key_idx]);
			if (key_idx==2){key_idx=-1;}
		});
		*/
		/* Action */
		var act = {
			ch : function(){
				menuID = 0;
				pgIndex = 1;
				$("#wrap").removeClass("list info ch vod");
				$("#wrap").addClass("ch");
			},
			list : function(){
				menuID = 1;
				epIndex = -1;
				$("#wrap").removeClass("list info ch vod");
				$("#wrap").addClass("list");
				$("#list ul li").removeClass("select");
				$("#list ul li").removeClass("focus");
				$(allPgObject[pgIndex]).addClass("select");
				$(allPgObject[pgIndex]).addClass("focus");
				$("#list ul").css({top : pgIndex * -147},300);
			},
			info : function(){
				menuID = 2;
				//epIndex = 0;
				$("#wrap").removeClass("list info ch vod");
				$("#wrap").addClass("info");
			},
			vod : function(){
				menuID = 3;
				/* Video Bg Stop */
				stopMediaBg();
				playMediaBg();

				$("#wrap").removeClass("list info ch vod");
				$("#wrap").addClass("vod");

				video = getVideo();
				playMedia();
				video.onPlayStateChange = playStateChange;
				video.onBuffering = buffering;
				progressBarWidth=$('#progressBg').width();

				showPlayer();
				triggerHide();

				$("#buttonLayout ul li").each(function(i){
					$(this).on("mouseenter", function(event){
						resetFocus();
						$(this).toggleClass(defaultClass[i]+"Hover" );
						cntIndex = i;
					});
				});

				var elem = $("#buttonLayout ul li");
				$("#buttonLayout ul li").click(function() {
					selectedButton();
				});

				for (i = 0; i < elem.length; i++) {
					allMenuObject.push(elem[i]);
				}
				$(allMenuObject[1]).toggleClass(defaultClass[1]+"Hover");

				//on mousemove, show player controls
				$('.playerLayout').on("mousemove ",function(event){
					showPlayer();
					triggerHide();
				});
				//to hideplayer
				/*
				$('#videoHolder').on("click",function(event){
					hidePlayer();
				});
				*/
			}
		};

		/* on mouseenter of progressBall class, change to progressBallHover class */
		$("#progressBall").on("mouseenter", function(event){
			if (video.playState==1){
				resetFocus();
				$(this).toggleClass("progressBallHover");
				//rowID=2;
				cntIndex = i;
		/* to drag on progressBar, video plays from where progressBall will be pointing*/
				$(".progressBallHover").draggable({
					axis: 'x',
					disabled: false,
					containment:'#ballCoverage',
					start: function(event, ui){
						dragged=true;
					},
					stop: function(event, ui){
						var xmove=ui.position.left;
						var seekedTime=(xmove/progressBarWidth)*videoPlayInfo.duration;
						video.seek(seekedTime);
					}
				});
			 }
		});
		$("#progressBall").on("mouseleave",function(event){
			$(".progressBallHover").draggable("disable");
	   });

		/*
		Function keydown()
		@param -event
		@Description - This has the implementation of keydown like lfet right up and donw
		Returns  -void
		*/
		$(document).keydown(function(event) {
			var key = event.keycode || event.which;
			switch(key){
				case VK_BACK :
					if(menuID == 0) {
						if (gbsubIndex == -1) {
							if (window.NetCastBack) {
								window.NetCastBack();
							}
						} else {
							switch(gbsubIndex) {
								case 0:
									gbsubIndex=-1;
									$("#wrap").removeClass("mypage");
									break;
								case 1:
									gbsubIndex=-1;
									$("#wrap").removeClass("search");
									break;
								case 2:
									gbsubIndex=-1;
									$("#mask,#event").hide();
									//$("#event,#mask").hide();
									break;
								case 3:
									$("#mask,#pop").hide();
									gbsubIndex=-1;
									break;
							}
						}
					} else if (menuID == 1) {
						if (epIndex == -1) {
							act.ch();
						} else {
							epIndex = -1;
							$("#info .scroll ul li").removeClass("select");
							$("#info .scroll ul li").removeClass("focus");

							$("#list ul li").removeClass("select");
							$("#list ul li").removeClass("focus");
							$(allPgObject[pgIndex]).addClass("select");
							$(allPgObject[pgIndex]).addClass("focus");
							$("#list ul").css({top : pgIndex * -147},300);
						}
					} else if (menuID == 2) {
						if (plindex == 0) {
							act.list();
						} else {
							$(".box-info ul li").removeClass("focus");
							$("#info .scroll ul li").removeClass("select");
							$("#info .scroll ul li").removeClass("focus");
							$(allEpObject[epIndex]).addClass("select");
							$(allEpObject[epIndex]).addClass("focus");
							plindex = 0;
						}
					} else if (menuID == 3) {
						stopMedia();
						resetFocus();
						$('.playerLayout').on("mousemove ",function(event){
							showPlayerReset();
						});
						playMediaBg();
						hidePlayer();
						act.info();
					}
					break;
				case VK_RIGHT :
					if(menuID == 0) {
						gbMenu = 1;
						setFocusGb(1);
					} else if (menuID == 1) {
						epIndex = 0;
						$("#info .scroll ul li").removeClass("select");
						$("#info .scroll ul li").removeClass("focus");
						$(allEpObject[epIndex]).addClass("select");
						$(allEpObject[epIndex]).addClass("focus");
					} else if (menuID == 2) {
						if (plindex == 0) {
							$(".box-info ul li").addClass("focus");
							plindex = 1;
						}
					}
					break;
				case VK_LEFT :
					if(menuID == 0) {
						if (gbMenu == 1) {
							setFocusGb(-1);
						}
					} else if (menuID == 1) {
						if (epIndex == -1) {
							act.ch();
						} else {
							epIndex = -1;
							$("#info .scroll ul li").removeClass("select");
							$("#info .scroll ul li").removeClass("focus");

							$("#list ul li").removeClass("select");
							$("#list ul li").removeClass("focus");
							$(allPgObject[pgIndex]).addClass("select");
							$(allPgObject[pgIndex]).addClass("focus");
							$("#list ul").css({top : pgIndex * -147},300);
						}
					} else if (menuID == 2) {
						if (plindex == 0) {
							act.list();
						} else {
							$(".box-info ul li").removeClass("focus");
							$("#info .scroll ul li").removeClass("select");
							$("#info .scroll ul li").removeClass("focus");
							$(allEpObject[epIndex]).addClass("select");
							$(allEpObject[epIndex]).addClass("focus");
							plindex = 0;
						}
					} else if (menuID == 3) {
						stopMedia();
						resetFocus();
						$('.playerLayout').on("mousemove ",function(event){
							showPlayerReset();
						});
						playMediaBg();
						hidePlayer();
						act.info();
					}
					break;
				case VK_UP :
					if (menuID == 0) {
						if (gbMenu == 0) {
							setFocus(-1);
						} else if (gbMenu == 1) {
							if (gbIndex > 3) {
								setFocusGb(-1);
							}
						}
					} else if (menuID == 1) {
						setFocus(-1);
					}  else if (menuID == 2) {
						if (plindex == 0) {
							setFocus(-1);
						}
					} else if (menuID == 3) {

					}
					break;
				case VK_DOWN :
					if (menuID == 0) {
						if (gbMenu == 0 ) {
							setFocus(1);
						} else if (gbMenu ==1) {
							if (gbIndex > 3) {
								setFocusGb(1);
							} else {
								gbIndex = 3;
								setFocusGb(1);
							}
						}
					} else if (menuID == 1) {
						setFocus(1);
					}  else if (menuID == 2) {
						if (plindex == 0) {
							setFocus(1);
						}
					} else if (menuID == 3) {

					}
					break;
				case VK_ENTER :
					//alert("ENTER");
					//$(".playerBottom").is(":visible")? selectedButton():"";
					// console.log(">>> gbMenu : " + gbMenu);
					if (menuID == 0) {
						if(gbMenu == 0) {
							act.list();
						} else {
							if (gbIndex > -1) {
								switch(gbIndex) {
									case 0:
										gbsubIndex=0;
										$("#wrap").removeClass("search");
										if (loginResultVal) {
											$("#wrap").toggleClass("mypage");
										} else {
											membership.requestLogin();
											membership.onRequestLogin = eventRequestLogin;
										}
										break;
									case 1:
										gbsubIndex=1;
										$("#wrap").removeClass("mypage");
										$("#wrap").toggleClass("search");
										break;
									case 2:
										gbsubIndex=2;
										$("#wrap").removeClass("mypage search");
										$("#mask,#event").show();
										break;
									case 3:
										break;
									case 4:
										gbsubIndex=3;
										$("#mask,#pop").show();
										break;
									case 5:
										gbsubIndex=3;
										$("#mask,#pop").show();
										break;
								}
							}
						}
					} else if (menuID == 1) {
						if (epIndex != -1) {
							act.info();
						} else {
							epIndex = 0;
							$("#info .scroll ul li").removeClass("select");
							$("#info .scroll ul li").removeClass("focus");
							$(allEpObject[epIndex]).addClass("select");
							$(allEpObject[epIndex]).addClass("focus");
						}
					} else if (menuID ==2) {
						if (plindex == 0) {
							$(".box-info ul li").addClass("focus");
							plindex = 1;
						} else {
							act.vod();
						}
					} else if (menuID == 3) {
						if ($(".control").css("display") == "none") {
							showPlayer();
							triggerHide();
						} else {
							hidePlayer();
						}
					}
					break;
			}
			//showPlayer();
			//triggerHide();
		});

	});

	/* BG Video Start */
	/*
	Function playMediaBg()
	@param- none
	@Description- plays & pauses the video
	Returns- none
	*/
	function playMediaBg()
	{
		stopped=false;
		if(video.playState == 0 || video.playState == 5)
		{
			loadDataSrcBg(true);
		}
		if(video.playState == 2)
		{
			//play
			loadDataSrcBg(true);
			video.play(1);
		} else if (video.playState == 1)
		{
			//pause
			video.play(0);
		}
	}
	/*
	Function stopMediaBg()
	@param- none
	@Description- stops the running video
	Returns- none
	*/
	function stopMediaBg()
	{
		stopped=true;
		// videoBg.currentTime=videoBg.duration;
	}
	/*
	Function loadDataSrcBg()
	@param- autoplay, to strt the video without clicking play button
	@Description- sets the source to video object
	Returns- none
	*/
	function loadDataSrcBg(auto)
	{
		/*
		var vidBgPath=videoArrayBg[vidIndex];
		if(checkFileExtensions(vidBgPath)){
			isSupp=videoBg.canPlayType(currentType);
			videoBg.src=vidBgPath;
			videoBg.type="video/"+currentType;
			videoBg.autoplay=auto;
		}
		else{
			console.log("BG video not supported");
		}
		*/
		var vidBgPath=videoArrayBg[vidIndex];
		if(checkFileExtensions(vidBgPath)){
			video.data = vidBgPath;
			video.play(1);
		}
		else{
			console.log("video not supported");
		}

	}
	/* BG Video End */

	/*
	Function setFocus()
	@param -button index
	@Description - This changes the color of the button from normal to focus (mouse over or remote keynavigation)
	Returns  -void
	*/
	function setFocus(idx){
		if (menuID == 0) {
			if (allChObject[chIndex + idx] != undefined) {
				chIndex=chIndex+idx;
				$("#wrap li,.btn_prev,.btn_next,.input,dl").removeClass("focus");
				$("#ch li").removeClass("select");
				$(allChObject[chIndex]).addClass("select");
				$("#ch ul").css({top : chIndex * -88},300);
				$("#list h1 img").attr({"src":"img/tit_"+(chIndex+1)+".png"});
				$("#info h2 img").attr({"src":"img/tit_"+(chIndex+1)+".png"});
			}
		}

		if (menuID == 1 && epIndex == -1) {
		//if (menuID == 1) {
			if (allPgObject[pgIndex + idx] != undefined) {
				pgIndex=pgIndex+idx;
				$("#list ul li").removeClass("select");
				$("#list ul li").removeClass("focus");
				$(allPgObject[pgIndex]).addClass("select");
				$(allPgObject[pgIndex]).addClass("focus");
				$("#list ul").css({top : pgIndex * -147},300);
			}
			console.log(">> epIndex == -1 ");
		}

		if (menuID == 1 && epIndex != -1) {
			if (allEpObject[epIndex + idx] != undefined) {
				epIndex=epIndex+idx;
				$("#info .scroll ul li").removeClass("select");
				$("#info .scroll ul li").removeClass("focus");
				$(allEpObject[epIndex]).addClass("select");
				$(allEpObject[epIndex]).addClass("focus");
				$("#info .scroll ul").css({top : epIndex * -50},300);
			}
			console.log(">> epIndex != -1 ");
		}

		if (menuID == 2) {
			if (allEpObject[epIndex + idx] != undefined) {
				epIndex=epIndex+idx;
				$("#info .scroll ul li").removeClass("select");
				$("#info .scroll ul li").removeClass("focus");
				$(allEpObject[epIndex]).addClass("select");
				$(allEpObject[epIndex]).addClass("focus");
				$("#info .scroll ul").css({top : epIndex * -50},300);
			}
		}
	}


	/*
	Function setFocusGb()
	@param -button index
	@Description - This changes the color of the button from normal to focus (mouse over or remote keynavigation)
	Returns  -void
	*/
	function setFocusGb(idx){
		if (menuID == 0) {
			if (allGbObject[gbIndex + idx] != undefined) {
				gbIndex=gbIndex+idx;
				$("#global li").removeClass("focus");
				$(allGbObject[gbIndex]).addClass("focus");
			} else {
				gbMenu=0;
				gbIndex = -1;
				$("#global li").removeClass("focus");
			}
		}
	}

	/*
	Function triggerHide()
	@param -none
	@Description - This triggers the hide function in 5 seconds
	Returns  -void
	*/
	function triggerHide(){
		if (video.playState == 1 || video.playState == 4 || video.playState == 2) {
			clearTimeout(hideTimerId);
			hideTimerId=setTimeout("hidePlayer()", 5000);
		}
	}

	/*
	Function hidePlayer()
	@param -none
	@Description - function to hide the player controls
	Returns  -void
	*/
	function hidePlayer(){
		// $(".playerBottom").hide(100);
		$(".control").hide(100);
	}

	/*
	Function showPlayer()
	@param -none
	@Description - function to show the player controls
	Returns  -void
	*/
	function showPlayer(){
		// $(".playerBottom").show();
		$(".control").show();
	}

	function showPlayerReset(){
		$(".control").hide();
	}

	/*
	Function setFocus()
	@param -button index
	@Description - This changes the color of the button from normal to focus (mouse over or remote keynavigation)
	Returns  -void
	function setFocus(idx){
		if(rowID==1){
			if (allMenuObject[cntIndex + idx] != undefined) {
				resetFocus();
				cntIndex=cntIndex+idx;
				$(allMenuObject[cntIndex]).addClass(defaultClass[cntIndex]+"Hover");
			}

		}
		else if(rowID==2){
			if(idx!=0){
				idx==1?forwardMedia():rewindMedia();
			}
			else{
					resetFocus();
					$("#progressBall").addClass("progressBallHover");
			}
		}
		else if(rowID==3){
			if (allExitObject[cntIndex + idx] != undefined) {
				resetFocus();
				cntIndex=cntIndex+idx;
				$(allExitObject[cntIndex]).addClass(exitBtnClass[cntIndex]+"Hover");
			}
		}
	}
	*/
	/*
	Function resetFocus()
	@param - none
	@Description - This changes the color of the button from focus to noramal (mouse over or remote keynavigation)
	Returns  -void
	*/
	function resetFocus(){
		$("#buttonLayout li").each(function(i){
			$(allMenuObject[i]).removeClass(defaultClass[i]+"Hover");
		});
		/*
		$(".keyHelp div").each(function(i){
			$(allExitObject[i]).removeClass(exitBtnClass[i]+"Hover");
		});
		*/
		$("#progressBall").removeClass("progressBallHover");
	}

	/*
	Function playStateChange()
	@param - none
	@Description - Depending upon the Video Playstate, the functions are called.
	Returns  -void
	*/
	function playStateChange()
	{
		if (video.playState == 0 ) {
			resetProgress();
		}else if( video.playState == 5){
			resetProgress();
			vidIndex<videoArray.length-1 ?vidIndex++:vidIndex=0;
			playMedia();
		}
		else if (video.playState == 1) {
			$('#progressBall').attr('class', 'progressBall');
			triggerHide();
			getVideoSourceInfo();
			getVideoPlayInfo();
		} else if (video.playState == 6) {
			//notifyError;
		}
	}
	/*
	Function buffering()
	@param - none
	@Description - It implements the buffering of the video. As video buffers, the progress bar will
	gradually increases with light pink color, showing the buffering progress
	Returns  -void
	*/
	function buffering()
	{
		videoPlayInfo = video.mediaPlayInfo();
		if(videoPlayInfo)
		{
			 if(videoPlayInfo.bufRemain!=-1){
				var bufferPos= Math.ceil((videoPlayInfo.bufRemain/videoPlayInfo.duration)*progressBarWidth);
				var pos=videoPlayInfo.duration-videoPlayInfo.bufRemain;
				if(pos != 0)
				{
					pos=(pos/videoPlayInfo.duration)*progressBarWidth;
					bufferPos+=pos;
					setBufferPosition(bufferPos);
				}
			 }
		}
		if (video.playState == 4) {
			setTimeout("buffering()", 100);
			//setTimeout("buffering()", 3000);
		}
	}
	/*
	Function setBufferPosition()
	@param - position
	@Description - to show the buffering progress
	Returns  -void
	*/
	function setBufferPosition(position)
	{
			$("#progressBuffer").addClass("progress progressBuffer");
			$("#progressBuffer").css("width",position+'px');
	}

	/*
	Function selectedButton()
	@param -obj-the current selected HTML object
	@Description - This function implements the on Enter function of remote or mouse click.
	Returns  -void
	*/
	function selectedButton()
	{
		switch(cntIndex){
			case 0: //stops the playing video
				stopMedia();
				break;
			case 1://plays the video
				playMedia();
				break;
			case 2: //rewinds the video
				rewindMedia();
				break;
			case 3: //forwards the video
				forwardMedia();
				break;
			case 4: //opens window for settings
				optionMedia();
				break;
		}
	}
	/*
	Function getVideo()
	@param- none
	@Description- gets the object of video
	Returns- video object
	*/
	function getVideo() {
		return document.getElementById('video');
	}
	/*
	Function resetProgress()
	@param- none
	@Description- resets all the functionalities, when video is stopped or video is finished
	Returns- none
	*/
	function resetProgress(){

		clearTimeout(playTimerId);
		clearTimeout(hideTimerId);
		showPlayer();
		$("#progressBarStatus").css("width",'0px');
		$('#progressBall').attr('class', 'progressBallInitial');
		if(dragged){
			$('.progressBallInitial').draggable("disable");
		}
		dragged=false;
		$('#progressBall').css("left",'0px');
		$("#progressBuffer").css("width",'0px');
		$("#play > img").remove();
		$('#play').append('<img src="img/player_btn_icon/movie_btn_icon_play_n.png" class="center" />');
		$("#remainingTime").text("");
		$("#totalTime").text("");
		$(".runningMovieName").text("");
		$(".runningMovieType").text("");
		resetFocus();
		cntIndex=1;
		rowID=1;
		mouseDown =false;
		$(allMenuObject[1]).toggleClass(defaultClass[1]+"Hover");
	}
	/*
	Function getTimeFromMS()
	@param- none
	@Description- to convert the millisecond in hr:min:sec formatted way
	Returns- none
	*/
	function getTimeFromMS(msec)
	{
		var time = Math.round(msec / 1000);
		var hours = Math.floor(time / 3600);
		var mins = Math.floor((time % 3600) / 60);
		var secs = Math.floor((time % 3600) % 60);

		if (hours < 10)
			hours = "0" + hours;
		if (mins < 10)
			mins = "0" + mins;
		if (secs < 10)
			secs = "0" + secs;

		return hours + ":" + mins + ":" + secs;

	}
	/*
	Function setPosition()
	@param - position
	@Description - to show the running video progress, it keeps track of
	progress status bar & progress ball as video runs.
	Returns  -void
	*/
	function setPosition(position)
	{
			$("#progressBarStatus").addClass("progress progressBarStatus");
			$("#progressBarStatus").css("width",position+'px');
			if(rowID==2){
				$('#progressBall').css("left",position-14+'px');
			}else{
				$('#progressBall').css("left",position+'px');
			}
	}
	/*
	Function getVideoPlayInfo()
	@param- none
	@Description- to get the playing video information
	Returns- none
	*/

	function getVideoPlayInfo() {
		videoPlayInfo = video.mediaPlayInfo();
		if (videoPlayInfo) {
			if ((video.playState != 5) && (video.playState != 0) && (video.playState != 2) ) {
				$("#remainingTime").text(getTimeFromMS(videoPlayInfo.currentPosition));
				// $("#totalTime").text(" / " + getTimeFromMS(videoPlayInfo.duration));
				$("#totalTime").text(getTimeFromMS(videoPlayInfo.duration));
				var pos=Math.ceil((videoPlayInfo.currentPosition/videoPlayInfo.duration)*progressBarWidth);
				setPosition(pos);
				playTimerId=setTimeout("getVideoPlayInfo()", 100);
			}
		}
	}
	/*
	Function getVideoSourceInfo()
	@param- none
	@Description- to get the playing video's source information
	Returns- none
	*/
	function getVideoSourceInfo() {
		var videoSourceInfo = video.getSrcInfo();
		videoSourceInfo.title!=null?$(".runningMovieName").text(videoSourceInfo.title):"";
	}
	/*
	Function loadDataSrc()
	@param- autoplay, to strt the video without clicking play button
	@Description- sets the source to video object
	Returns- none
	*/
	function loadDataSrc(auto)
	{
		var vidPath=videoArray[vidIndex];
		if(checkFileExtensions(vidPath)){
			// video.data ="media/"+vidPath;
			video.data = vidPath;
			video.play(1);
		}
		else{
			console.log("video not supported");
		}
	}
	/*
	Function stopMedia()
	@param- none
	@Description- stops the running video
	Returns- none
	*/
	function stopMedia()
	{
		if (video.playState != 0)
		video.stop();
	}
	/*
	Function playMedia()
	@param- none
	@Description- plays & pauses the video
	Returns- none
	*/
	function playMedia()
	{
		console.log(">>>>> PlayMedia");
		console.log(">>>>> video.playState : " + video.playState);

		loadDataSrc(true);

		if(video.playState == 0 ||video.playState == 5)
		{
			loadDataSrc(true);
			$("#play > img").remove();
			$('#play').append('<img src="img/player_btn_icon/movie_btn_icon_pause_n.png" class="center" />');

		}
		if(video.playState == 2)
		{
			//play
			video.play(1);
			$("#play > img").remove();
			$('#play').append('<img src="img/player_btn_icon/movie_btn_icon_pause_n.png" class="center" />');
		}else if(video.playState == 1)
		{
			//pause
				video.play(0);
				$("#play > img").remove();
				$('#play').append('<img src="img/player_btn_icon/movie_btn_icon_play_n.png" class="center" />');
		}
	}

	/*
	Function forwardMedia()
	@param- none
	@Description- forwards the running video by 10sec.
	Returns- none
	*/
	function forwardMedia()
	{
		if (video.playState != 4 && video.playState == 1) {
			if (video.isSeekable) {
				if ((video.playPosition + (TIME_FOR_SEEK * 1000)) < videoPlayInfo.duration * 1000) {
					video.seek(video.playPosition + (TIME_FOR_SEEK * 1000));
				} else {
					video.seek(videoPlayInfo.duration);
				}
			}
		}
	}
	/*
	Function rewindMedia()
	@param- none
	@Description- rewinds the running video by 10sec.
	Returns- none
	*/
	function rewindMedia()
	{
		if (video.playState != 4 && video.playState == 1) {
			if (video.isSeekable) {
				if ((video.playPosition - (TIME_FOR_SEEK * 1000)) > 0) {
					video.seek(video.playPosition - (TIME_FOR_SEEK * 1000));
				} else {
					video.seek(0);
				}
			}
		}
	}
	/*
	Function optionMedia()
	@param- none
	@Description- opens window for settings
	Returns- none
	*/
	function optionMedia()
	{
		  if(window.NetCastLaunchQMENU) {
			  window.NetCastLaunchQMENU();
		  }
	}

	function checkRuc(str) {
		alert(str);
	}

	/*
	Function checkFileExtensions()
	@param- url the videotype
	@Description- checks for the supported formats
	Returns- none
	*/
	function checkFileExtensions (url) {
		  for (var i = 0; i < supportedMimeTypes.length; i++) {
				if (url.lastIndexOf(supportedMimeTypes[i]) > 0) {
					return true;
				}
			}
			return false;
	}

	function eventRequestLogin(e) {
		if(e) {
			var result = e.result;
			var errorCode = e.errorCode;
			var userID = e.userID;
			// console.log(">>>>>>>>>> result : " + result);
			console.log(">>>>>>>>>> errorCode : " + errorCode);
			// console.log(">>>>>>>>>> userID : " + userID);
			if (result) {
				loginResultVal = result;
				userLgoinId = userID;
				$("#user").removeClass("logout").addClass("login");
				$("#user b").html(userLgoinId);
			}
		} else {
			console.log("Event not exist!!!" + e);
		}
		stopMedia();
		playMediaBg();
	};
})();